package day03.text03;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client implements Runnable {

    String ip;
    int port;

    public Client(String ip, int port) {
        this.ip = ip;
        this.port = port;
    }

    @Override
    public void run() {
        Socket socket = null;
        try {
            socket = new Socket(ip, port);
        } catch (IOException e) {
            e.printStackTrace();
        }
        while (true) {
            try {
                OutputStream outputStream = socket.getOutputStream();
                OutputStreamWriter ow = new OutputStreamWriter(outputStream,StandardCharsets.UTF_8);
                Scanner sc = new Scanner(System.in);
                String message = sc.next();
                ow.write(String.valueOf(message.getBytes(StandardCharsets.UTF_8)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        }
    }
